package com.game.eggscatcher.GameObjects;

import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pool.Poolable;
import com.game.eggscatcher.GameHelpers.AssetLoader;

public class Fallable implements Poolable{
	private Vector2 position;
	private int velocityY;
	private Rectangle boundingRect;
	public boolean alive;
	public boolean isTrung;
	public final int WIDTH = 8;
	public final int HEIGHT = 10;
	private boolean outScreen;
	
	public Fallable(){
		position = new Vector2();
		alive = false;
		outScreen = false;
		isTrung = true;
		boundingRect = new Rectangle();
	}
	
	public void init(float x, float y, int v, boolean isTrung) {
		position.set(x, y);
		velocityY = v;
		alive = true;
		this.isTrung = isTrung;
	}
	
	public void update(float delta) {
		if (position.y <= 204) position.y += velocityY * delta; 
		else {
			AssetLoader.dropped.play();
			alive = false;
			outScreen = true;
		}
		boundingRect.set(position.x, position.y, WIDTH, HEIGHT);
	}
	
	public void reset(float x, float y) {
		position.x = x;
		position.y = y;
	}
	public float getX() {
		return position.x;
	}
	public float getY() {
		return position.y;
	}
	public Rectangle getBound() {
		return boundingRect;
		
	}
	@Override
	public void reset() {
		position.set(0, 0);
		alive = false;
		outScreen = false;
		isTrung = true;
		boundingRect.setPosition(position);
	}
	public boolean isOutScreen() {
		return outScreen;
	}
	public boolean collides(Ro ro) {
		if (position.y > ro.getY()) {
			return Intersector.overlaps(boundingRect, ro.getBoundRect());
		}
		return false;
	}
}
